package com.fc.system.component;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fc.system.entity.DictCode;
import com.fc.system.service.DictCodeService;

@Service("dictHelper")
public class DictHelper {
    @Resource
    DictCodeService dictCodeService;

    @SuppressWarnings("rawtypes")
    public String show(String masterCode, Enum codeValue) {
        DictCode DictCode = dictCodeService.getByValue(masterCode, codeValue.name());
        return DictCode == null ? "" : DictCode.getCodeName();
    }

    public List<SelectDTO> select(String masterCode) {
        List<SelectDTO> selectList = new ArrayList<SelectDTO>();

        DictCode DictCode = new DictCode();
        DictCode.setMasterCode(masterCode);
        List<DictCode> details = dictCodeService.find(masterCode);
        for (DictCode detail : details) {
            selectList.add(new SelectDTO(detail.getCodeName(), detail.getCodeValue()));
        }
        return selectList;
    }

    public static class SelectDTO {
        public String name;
        public String val;

        public SelectDTO(String name, String val) {
            super();
            this.name = name;
            this.val = val;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getVal() {
            return val;
        }

        public void setVal(String val) {
            this.val = val;
        }
    }
}